const initState = [
    { id: 1, name: '吃饭', isDone: false },
    { id: 2, name: '睡觉', isDone: true }
]



export default function todo (state = initState, action) {
    const { payload } = action
    switch (action.type) {

        case 'todo/del':
            return state.filter(item => item.id !== payload)

        case 'todo/add':
            return [payload, ...state]

        case 'todo/changeState':

            return state.map(item => {
                if (item.id === payload.id) {
                    item.isDone = payload.flag

                }
                return item
            })




        default:
            return state

    }




}
